package com.md.model;

import com.md.base.EnumBase;
import com.md.value.constants.ApiConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * 2024-10-11 18:18
 */
@Getter
@AllArgsConstructor
public enum ModuleEnum implements EnumBase {

  /**
   * 商品类别
   */
  GOODS_TYPE(0, ApiConstants.GOOD_TYPE, "/good-type"),
  /**
   * 用户
   */
  USERS(1, ApiConstants.USERS, "/users"),
  /**
   * 角色
   */
  ROLE(2, ApiConstants.ROLE, "/role"),
  /**
   * 日志
   */
  LOGS(3, ApiConstants.LOGS, "/logs"),
  /**
   * 接口
   */
  API(4, ApiConstants.API, "/apis"),
  /**
   * 鉴权
   */
  MAC(5, ApiConstants.MAC, "/mac"),
  /**
   * 系统
   */
  SYSTEM(6, ApiConstants.SYSTEM, "/system"),
  /**
   * 内部调用
   */
  INTERNAL(7, ApiConstants.INTERNAL, "/internal"),
  /**
   * 登录中心
   */
  LOGIN_CENTER(8, ApiConstants.LOGIN_CENTER, "/login-center");

  static final Map<Integer, ModuleEnum> ENUM_MAP = Arrays.stream(ModuleEnum.values())
    .collect(Collectors.toMap(EnumBase::getCode, e -> e));
  static final Map<String, ModuleEnum> ENUM_MAP_STRING = Arrays.stream(ModuleEnum.values())
    .collect(Collectors.toMap(EnumBase::getMessage, e -> e));
  private final Integer code;
  private final String message;
  private final String path;

  public static ModuleEnum of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }

  public static ModuleEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }

}
